﻿using System;
using System.Windows.Controls;
using MineSweeping.AppCode;
using MineSweeping.AppCode.Tops;

namespace MineSweeping
{
    public partial class TopsPage
    {
        private static readonly LocalTop localTop = new LocalTop();

        public TopsPage()
        {
            InitializeComponent();

            switch (App.Context.Difficulty)
            {
                case Difficulty.Easy:
                    radioLocalEasy.IsChecked = true;
                    break;
                case Difficulty.Medium:
                    radioLocalMedium.IsChecked = true;
                    break;
                case Difficulty.Hard:
                    radioLocalHard.IsChecked = true;
                    break;
            }
        }

        private void OnLocalButtonChecked(object sender, System.Windows.RoutedEventArgs e)
        {
            this.Dispatcher.BeginInvoke
                (
                    ()=>
                        {
                            RadioButton difficultyButton = sender as RadioButton;

                            switch (difficultyButton.Name)
                            {
                                case "radioLocalEasy":
                                    listLocalTops.ItemsSource = localTop.GetTopItemsByLevel(Difficulty.Easy);
                                    break;
                                case "radioLocalMedium":
                                    listLocalTops.ItemsSource = localTop.GetTopItemsByLevel(Difficulty.Medium);
                                    break;
                                case "radioLocalHard":
                                    listLocalTops.ItemsSource = localTop.GetTopItemsByLevel(Difficulty.Hard);
                                    break;
                            }

                            storyShowLocalTops.Begin();
                        }
                );
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            NavigationService.GoBack();
            e.Cancel = true;
        }

        private void btnBack_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            NavigationService.GoBack();
        }

        private void btnVote_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/About.xaml", UriKind.Relative));
        }
    }
}